package by.bucha.testproject.service.handlers.impl;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.ResultReceiver;
import by.bucha.testproject.service.ApplicationService;
import by.bucha.testproject.service.handlers.BaseHandler;

public class DbDeleteHandler extends BaseHandler {

	@Override
	public void doExecute(final Intent intent, final Context context,
			ResultReceiver callback) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				Uri uri = Uri.parse(intent
						.getStringExtra(ApplicationService.EXTRA_URI));

				String selection = intent
						.getStringExtra(ApplicationService.EXTRA_SELECTION);
				String[] selectionArgs = intent
						.getStringArrayExtra(ApplicationService.EXTRA_SELECTION_ARGS);
				int number = context.getContentResolver().delete(uri,
						selection, selectionArgs);

				Bundle bundle = new Bundle();
				bundle.putInt(ApplicationService.EXTRA_ROWS_NUMBER_DELETED,
						number);

				sendUpdate(SUCCESS_RESPONSE, bundle);
			}
		}).start();
	}
}
